Telegram Group & Telegram Channel
📍 How to: кэширование в Python с помощью flexicache

В Python удобно использовать декораторы для кэширования результатов функций и методов — как в оперативной памяти, так и во временных хранилищах вроде memcached. Один из наиболее гибких инструментов для этого — flexicache из библиотеки fastcore.

flexicache — это декоратор, который поддерживает:
• LRU-кэширование (удаление наименее используемых элементов),
• политику истечения кэша по времени — time_policy,
• инвалидирование кэша при изменении файла — mtime_policy.

➡️ Пример: time_policy
@flexicache(time_policy(0.1))
def random_func():
return randint(1, 1000)

assert random_func() == random_func()
sleep(0.2)
assert random_func() != random_func()


➡️ Пример: mtime_policy. Инвалидирование при изменении файла main.py
@flexicache(mtime_policy('main.py'))
def random_func():
return randint(1, 1000)

Path('main.py').touch() # обновление времени изменения


➡️ Пример: совмещение политик
@flexicache(time_policy(0.1), mtime_policy('main.py'))
def random_func():
return randint(1, 1000)


Кэш сбрасывается либо по времени, либо при обновлении файла — в зависимости от того, что произойдёт первым.

➡️ Пример: LRU-кэширование
@flexicache(maxsize=2)
def random_func(v):
return randint(1, 1000)

random_func(1)
random_func(2)
random_func(3) # результат для аргумента 1 будет удалён


➡️ Пример: удобный timed_cache. Для кэша с таймаутом и ограничением размера
from fastcore.xtras import timed_cache

@timed_cache(0.1, maxsize=2)
def random_func(v):
return randint(1, 1000)


📌 flexicache — гибкий и мощный инструмент для продвинутого кэширования в Python. Поддерживает политики истечения, комбинирование стратегий и заменяет стандартный lru_cache.

Библиотека питониста #буст
Please open Telegram to view this post
VIEW IN TELEGRAM



tg-me.com/pyproglib/6711
Create:
Last Update:

📍 How to: кэширование в Python с помощью flexicache

В Python удобно использовать декораторы для кэширования результатов функций и методов — как в оперативной памяти, так и во временных хранилищах вроде memcached. Один из наиболее гибких инструментов для этого — flexicache из библиотеки fastcore.

flexicache — это декоратор, который поддерживает:
• LRU-кэширование (удаление наименее используемых элементов),
• политику истечения кэша по времени — time_policy,
• инвалидирование кэша при изменении файла — mtime_policy.

➡️ Пример: time_policy

@flexicache(time_policy(0.1))
def random_func():
return randint(1, 1000)

assert random_func() == random_func()
sleep(0.2)
assert random_func() != random_func()


➡️ Пример: mtime_policy. Инвалидирование при изменении файла main.py
@flexicache(mtime_policy('main.py'))
def random_func():
return randint(1, 1000)

Path('main.py').touch() # обновление времени изменения


➡️ Пример: совмещение политик
@flexicache(time_policy(0.1), mtime_policy('main.py'))
def random_func():
return randint(1, 1000)


Кэш сбрасывается либо по времени, либо при обновлении файла — в зависимости от того, что произойдёт первым.

➡️ Пример: LRU-кэширование
@flexicache(maxsize=2)
def random_func(v):
return randint(1, 1000)

random_func(1)
random_func(2)
random_func(3) # результат для аргумента 1 будет удалён


➡️ Пример: удобный timed_cache. Для кэша с таймаутом и ограничением размера
from fastcore.xtras import timed_cache

@timed_cache(0.1, maxsize=2)
def random_func(v):
return randint(1, 1000)


📌 flexicache — гибкий и мощный инструмент для продвинутого кэширования в Python. Поддерживает политики истечения, комбинирование стратегий и заменяет стандартный lru_cache.

Библиотека питониста #буст

BY Библиотека питониста | Python, Django, Flask




Share with your friend now:
tg-me.com/pyproglib/6711

View MORE
Open in Telegram


Библиотека питониста | Python Django Flask Telegram | DID YOU KNOW?

Date: |

How to Invest in Bitcoin?

Like a stock, you can buy and hold Bitcoin as an investment. You can even now do so in special retirement accounts called Bitcoin IRAs. No matter where you choose to hold your Bitcoin, people’s philosophies on how to invest it vary: Some buy and hold long term, some buy and aim to sell after a price rally, and others bet on its price decreasing. Bitcoin’s price over time has experienced big price swings, going as low as $5,165 and as high as $28,990 in 2020 alone. “I think in some places, people might be using Bitcoin to pay for things, but the truth is that it’s an asset that looks like it’s going to be increasing in value relatively quickly for some time,” Marquez says. “So why would you sell something that’s going to be worth so much more next year than it is today? The majority of people that hold it are long-term investors.”

Telegram Be The Next Best SPAC

I have no inside knowledge of a potential stock listing of the popular anti-Whatsapp messaging app, Telegram. But I know this much, judging by most people I talk to, especially crypto investors, if Telegram ever went public, people would gobble it up. I know I would. I’m waiting for it. So is Sergei Sergienko, who claims he owns $800,000 of Telegram’s pre-initial coin offering (ICO) tokens. “If Telegram does a SPAC IPO, there would be demand for this issue. It would probably outstrip the interest we saw during the ICO. Why? Because as of right now Telegram looks like a liberal application that can accept anyone - right after WhatsApp and others have turn on the censorship,” he says.

Библиотека питониста | Python Django Flask from fr


Telegram Библиотека питониста | Python, Django, Flask
FROM USA